package test_junit_shop.ProductStock;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import util.BaseDriver;

import java.util.List;

/**
 * Created by Eric on 2018/2/2.
 * 门店-采购退换货列表
 */
public class RefoundList extends BaseDriver {
    private static RefoundList rl = new RefoundList();
    public static RefoundList getInstance(){
        return rl;
    }

    private RefoundList() {
    }

    /**
     * 检查刚退货的数量是否正确
     * @param refundAmount 退货数量
     */
    public void checkRefound(String refundAmount) throws InterruptedException {
        driver.switchTo().defaultContent();
        List<WebElement> frameList = driver.findElements(By.xpath("//iframe[@name='iframeundefined']"));
        driver.switchTo().frame(frameList.get(frameList.size() - 1));

        Thread.sleep(1000);
        // 选择第一个行，即最新的退货项
        WebElement tmp = driver.findElement(By.xpath("//tbody/tr[1]/td[1]/input"));
        driver.findElement(By.xpath("//tbody/tr[1]/td[1]/input")).click();
        driver.findElement(By.xpath("//button[@onclick='detail()']")).click();

        Thread.sleep(2000);
        // 切换到详情窗体
        driver.switchTo().frame(0);
        WebElement refundAmountField =  driver.findElement(By.xpath("//tbody/tr[1]/td[2]"));
        System.out.println(Float.valueOf(refundAmount));
        System.out.println(Float.valueOf(refundAmountField.getText()));
        if (Float.valueOf(refundAmount).floatValue() == Float.valueOf(refundAmountField.getText()).floatValue()) {
            System.out.println("退换货数量正确！");
        } else {
            System.out.println("退换货数量错误！");
        }

        driver.switchTo().parentFrame();
        driver.findElement(By.linkText("取消")).click();
    }
}
